<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-input v-model="vo.name" placeholder="关键字查询" class="handle-input mr10"></el-input>
        <el-input v-model="vo.cid" placeholder="关键字查询" class="handle-input mr10"></el-input>
        <el-input v-model="vo.begin" placeholder="关键字查询1" class="handle-input mr10"></el-input>
        <el-input v-model="vo.end" placeholder="关键字查询2" class="handle-input mr10"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
        <br> <br>
        <el-button type="primary" icon="el-icon-search" @click="createPDF">生成PDF</el-button>
        <el-button type="primary" icon="el-icon-search" ><a :href="baseURL+'/student/download'">下载</a></el-button>
        <el-button type="primary" icon="el-icon-search" ><a :href="baseURL+'/student/preview'">预览</a></el-button>
      </div>
      <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="id" label=""></el-table-column>
        <el-table-column prop="name" label="学生姓名"></el-table-column>
        <el-table-column prop="sex" label="性别"></el-table-column>
        <el-table-column prop="cid" label="班级id"></el-table-column>
        <el-table-column prop="college" label="学院"></el-table-column>
        <el-table-column prop="birthday" label="生日"></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button type="text" icon="el-icon-delete" class="red" @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="currPage" :page-size="pageSize"
                       :total="pageTotal"
                       @current-change="handlePageChange"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'Student',
  data() {
    return {
      vo: {
      },
      currPage: 1,
      pageSize: 5,
      pageTotal: 10,
      baseURL: 'http://127.0.0.1:8082',
      tableData: [],
      multipleSelection: [],
      editVisible: false,

    };
  },
  created() {
    this.getData();
  },
  methods: {
    createPDF(){
      axios.get(this.$baseUrl+'/student/createPDF').then(res=>{
        if(res.data.flag){
          alert("操作成功")
        }
      })
    },

    download(){},
    preview(){},
    // 获取 easy-mock 的模拟数据
    getData() {
      axios.post(this.baseURL + '/student/search/' + this.currPage + '/' + this.pageSize, this.vo).then(res => {
        this.tableData = res.data.rows;
        this.pageTotal = res.data.total;
      })
    },
    // 触发搜索按钮
    handleSearch() {
      this.getData();
    },

    // 分页导航
    handlePageChange(val) {
      this.currPage = val;
      this.getData();
    },

  }
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>
